package com.tehui.utils.tools;

import android.content.Context;
import android.content.SharedPreferences;

import com.tehui.utils.ui.UiUtils;

/**
 * 关于SharedPreference的工具类
 */

public class PrefUtils {

    private static Context context = UiUtils.getContext();

    public static boolean getBoolean( String key, boolean defValue) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        boolean retBoolean = sp.getBoolean(key, defValue);
        return retBoolean;
    }

    public static void setBoolean(String key, boolean value) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(key, value);
        edit.commit();
    }

    public static String getString(String key, String defValue) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        String retString = sp.getString(key, defValue);
        return retString;
    }

    public static void setString(String key, String value) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public static int getInt(String key, int defValue) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        int retInt = sp.getInt(key, defValue);
        return retInt;
    }

    public static void setInt(String key, int value) {
        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putInt(key, value);
        edit.commit();
    }
}
